#include "stdafx.h"
//-------------------------------------------------------------------------------------------------
//PropertiesWnd.cpp : implementation of the CPropertiesWnd class      
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2011 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk July 2011
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------

#include <string>

#include "resource.h"
#include "ArchiveProcGUIDoc.h"

#include "PropertiesWnd.h"
#include "Resource.h"
#include "MainFrm.h"
#include "ArchiveProcGUI.h"

#include "SelectTool.h"
#include "ImagePropInteger.h"
#include "ImagePropTextLine.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

/////////////////////////////////////////////////////////////////////////////
// CResourceViewBar


IMPLEMENT_DYNAMIC( CPropertiesWnd, CDockablePane )

CPropertiesWnd::CPropertiesWnd()  :
	m_cxSize(0),
	m_cySize(0),
	m_ctrlComboHt(0),	
	m_ctrlMinHeaderHt(0),
	m_ctrlSliderHt(0),
	m_UpdatingUI(false),
	m_pSelImageObject('\0')
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::CPropertiesWnd()", "properties window ctor");
#endif
//!!!!!!!!!!!!!!!
	m_ClientRect.SetRectEmpty();
}

CPropertiesWnd::~CPropertiesWnd()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::~CPropertiesWnd()", "properties window dtor");
#endif
//!!!!!!!!!!!!!!!
}

BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_COMMAND(ID_EXPAND_ALL, OnExpandAllProperties)
	ON_UPDATE_COMMAND_UI(ID_EXPAND_ALL, OnUpdateExpandAllProperties)
	ON_WM_SETFOCUS()
	ON_WM_SETTINGCHANGE()
	ON_COMMAND(ID_EDIT_CUT, &CPropertiesWnd::OnEditCut)
	ON_COMMAND(ID_EDIT_COPY, &CPropertiesWnd::OnEditCopy)
	ON_COMMAND(ID_EDIT_PASTE, &CPropertiesWnd::OnEditPaste)
	ON_CBN_SELCHANGE (IDC_PROPSIMAGEOBJCB, OnImageObjectSelChange) 
	ON_CBN_SELCHANGE (IDC_PROPSIMAGETYPECB, OnImageTypeSelChange) 
	ON_NOTIFY(TRBN_THUMBPOSCHANGING, IDC_PROPSIMAGEBRIGHTNESS, &CPropertiesWnd::OnThumbChangeBrightness)
	ON_NOTIFY(TRBN_THUMBPOSCHANGING, IDC_PROPSIMAGECONTRAST, &CPropertiesWnd::OnThumbChangeContrast)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CResourceViewBar message handlers


void CPropertiesWnd::DoDataExchange(CDataExchange* pDX)
{
	DDX_Text(pDX, IDC_PROPSIMAGEREFHEADER, m_ImageDicomRef);
	DDX_Text(pDX, IDC_PROPSIMAGEOBJNOTES, m_ImageObjectNotes);
	DDX_Text(pDX, IDC_PROPSIMAGENOTES, m_ImageNotes);
	DDX_Control(pDX, IDC_PROPSIMAGEBRIGHTNESS, m_ImageBrightnessCtrl);
	DDX_Control(pDX, IDC_PROPSIMAGECONTRAST, m_ImageContrastCtrl);
	CDockablePane::DoDataExchange(pDX);
}


void CPropertiesWnd::AdjustLayout()
{
	if ( GetSafeHwnd() != NULL) 
	{
		CRect rectClient;
		GetClientRect(rectClient);

		if ( rectClient != m_ClientRect )
		{

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::AdjustLayout()", "(rectClient != m_ClientRect) so adjust layout of controls in properties window");
#endif
//!!!!!!!!!!!!!!!

			m_ClientRect = rectClient;

			int ctrlMajHeaderHt = ((m_ctrlMinHeaderHt * 3) / 2);
			int ctrlEditHt = 80;
			int ctrlPropsHt = 120;
			int ctrlSliderTextWd = 60;

			int ctrlTop = 0;

			UINT flags = SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW;

			ctrlTop = rectClient.top;
			m_ImageDicomRefCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), ctrlMajHeaderHt, flags);
			ctrlTop += ctrlMajHeaderHt;

			m_ImageBrightnessHeaderCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), m_ctrlSliderHt, flags);
			m_ImageBrightnessCtrl.SetWindowPos(NULL, rectClient.left + ctrlSliderTextWd, ctrlTop, rectClient.Width() - ctrlSliderTextWd, m_ctrlSliderHt, flags);
			ctrlTop += m_ctrlSliderHt;

			m_ImageContrastHeaderCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), m_ctrlSliderHt, flags);
			m_ImageContrastCtrl.SetWindowPos(NULL, rectClient.left + ctrlSliderTextWd, ctrlTop, rectClient.Width() - ctrlSliderTextWd, m_ctrlSliderHt, flags);
			ctrlTop +=  m_ctrlSliderHt;

			m_wndImageTypeCombo.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(),  m_ctrlComboHt, flags);
			ctrlTop +=   m_ctrlComboHt;

			m_ImageNotesHeaderCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), m_ctrlMinHeaderHt, flags);
			ctrlTop += m_ctrlMinHeaderHt;

			m_ImageNotesCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), ctrlEditHt, flags);
			ctrlTop += ctrlEditHt;

			m_wndImagePropList.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), ctrlPropsHt, flags);
			ctrlTop += ctrlPropsHt;

			m_SeperatorCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), ctrlMajHeaderHt, flags);
			ctrlTop += ctrlMajHeaderHt;

			m_ImageObjectHeaderCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), ctrlMajHeaderHt, flags);
			ctrlTop += ctrlMajHeaderHt;

			m_wndImageObjectCombo.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(),  m_ctrlComboHt, flags);
			ctrlTop +=   m_ctrlComboHt;

			m_ImageObjectNotesHeaderCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), m_ctrlMinHeaderHt, flags);
			ctrlTop += m_ctrlMinHeaderHt;

			m_ImageObjectNotesCtrl.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), ctrlEditHt, flags);
			ctrlTop += ctrlEditHt;

			m_wndImageObjectPropList.SetWindowPos(NULL, rectClient.left, ctrlTop, rectClient.Width(), rectClient.Height() - ctrlTop, flags);
		}
	}
	return;
}

int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	int  rc = -1;
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
		MxUtils::OutputDebugMsg("CPropertiesWnd::OnCreate()", "create properties window objects");
#endif
//!!!!!!!!!!!!!!!

	const char *errMsg = '\0';

	if (CDockablePane::OnCreate(lpCreateStruct) == -1)
		errMsg = "CDockablePane::OnCreate() failed";
	else
	{
		CRect rectDummy;
		rectDummy.SetRectEmpty();

		DWORD dwViewStyle = WS_VISIBLE | WS_CHILD;
		DWORD dwViewHeaderStyle = dwViewStyle | ES_READONLY | SS_LEFTNOWORDWRAP;
		DWORD dwViewComboStyle = dwViewStyle | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
		DWORD dwViewEditStyle = dwViewStyle |  ES_MULTILINE  | ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL;
		DWORD dwViewSliderStyle = dwViewStyle | TBS_NOTIFYBEFOREMOVE;

		if (!m_ImageDicomRefCtrl.Create(L"Image:", dwViewHeaderStyle, rectDummy, this, IDC_PROPSIMAGEREFHEADER))
			errMsg = "Failed to create image ref control";
		else if (!m_ImageBrightnessHeaderCtrl.Create(L"Brightness", dwViewHeaderStyle, rectDummy, this, IDC_PROPSIMAGEBRIGHTNESSHEADER))
			errMsg = "Failed to create image brightness header control";
		else if (!m_ImageBrightnessCtrl.Create(dwViewSliderStyle, rectDummy, this, IDC_PROPSIMAGEBRIGHTNESS))
			errMsg = "Failed to create image brightness control";
		else
		{
			m_ImageBrightnessCtrl.SetRange(ImageProps::BrightnessMin, ImageProps::BrightnessMax);
			m_ImageBrightnessCtrl.SetTic(atoi(ImageProps::BrightnessMid));

			CRect sliderRect;
			m_ImageBrightnessCtrl.GetThumbRect(&sliderRect);
			m_ctrlSliderHt = (sliderRect.Height() * 3) / 2;	//use for both brightness and contrast
		}

		if (errMsg == '\0')
		{
			if (!m_ImageContrastHeaderCtrl.Create(L"Contrast", dwViewHeaderStyle, rectDummy, this, IDC_PROPSIMAGECONTRASTHEADER))
				errMsg = "Failed to create image contrast header control";
			else if(!m_ImageContrastCtrl.Create(dwViewSliderStyle, rectDummy, this, IDC_PROPSIMAGECONTRAST))
				errMsg = "Failed to create image contrast control";
			else
			{
				m_ImageContrastCtrl.SetRange(ImageProps::ContrastMin, ImageProps::ContrastMax);
				m_ImageContrastCtrl.SetTic(atoi(ImageProps::ContrastMid));
			}
		}

		if (errMsg == '\0')
		{
			if (!m_wndImageTypeCombo.Create(dwViewComboStyle, rectDummy, this, IDC_PROPSIMAGETYPECB))
				errMsg = "Failed to create image type Combo";
			else
			{
				CRect comboRect;
				m_wndImageTypeCombo.GetClientRect(&comboRect);
				m_ctrlComboHt = comboRect.Height() - 1;
			}
		}

		if (errMsg == '\0')
		{
			if (!m_ImageNotesHeaderCtrl.Create(L"Notes:", dwViewHeaderStyle, rectDummy, this, IDC_PROPSIMAGENOTESHEADER))
				errMsg = "Failed to create image notes control";
			else if (!m_ImageNotesCtrl.Create(dwViewEditStyle, rectDummy, this, IDC_PROPSIMAGENOTES))
				errMsg = "Failed to create Notes control";
			else
			{
				m_ImageNotesCtrl.ShowScrollBar(SB_VERT);
				m_ImageNotesCtrl.SetScrollRange(SB_VERT, 0, 100);
				m_ImageNotesCtrl.ShowScrollBar(SB_HORZ);
				m_ImageNotesCtrl.SetScrollRange(SB_HORZ, 0, 100);
				m_ImageNotesCtrl.SetLimitText(ImageProps::NotesLengthMax);
			}
		}
		if (errMsg == '\0')
		{
			if (!m_wndImagePropList.Create(dwViewStyle, rectDummy, this, IDC_PROPSIMAGEPROPS))
				errMsg = "Failed to create Image Properties Grid";
			else
			{
				m_wndImagePropList.EnableHeaderCtrl(FALSE);
				m_wndImagePropList.EnableDescriptionArea();
				m_wndImagePropList.SetVSDotNetLook();
				m_wndImagePropList.MarkModifiedProperties();
				m_wndImagePropList.ExpandAll(FALSE);
				m_wndImagePropList.SetAlphabeticMode(FALSE);
			}
		}
	
		if (errMsg == '\0')
		{
			if (!m_SeperatorCtrl.Create(L"", dwViewHeaderStyle, rectDummy, this, IDC_PROPSIMAGEOBJNOTESHEADER))
				errMsg = "Failed to create separator control";
			else if (!m_ImageObjectHeaderCtrl.Create(L"Objects found in image", dwViewHeaderStyle, rectDummy, this, IDC_PROPSIMAGEOBJNOTESHEADER))
				errMsg = "Failed to create image object header control";
			else if (!m_wndImageObjectCombo.Create(dwViewComboStyle, rectDummy, this, IDC_PROPSIMAGEOBJCB))
				errMsg = "Failed to create image object Combo";
			else if (!m_ImageObjectNotesHeaderCtrl.Create(L"Notes:", dwViewHeaderStyle, rectDummy, this, IDC_PROPSIMAGEOBJNOTESHEADER))
				errMsg = "Failed to create image object notes control";
			else if (!m_ImageObjectNotesCtrl.Create(dwViewEditStyle, rectDummy, this, IDC_PROPSIMAGEOBJNOTES))
				errMsg = "Failed to create Notes control";
			else
			{
				m_ImageObjectNotesCtrl.ShowScrollBar(SB_VERT);
				m_ImageObjectNotesCtrl.SetScrollRange(SB_VERT, 0, 100);
				m_ImageObjectNotesCtrl.ShowScrollBar(SB_HORZ);
				m_ImageObjectNotesCtrl.SetScrollRange(SB_HORZ, 0, 100);
				m_ImageObjectNotesCtrl.SetLimitText(ImageProps::NotesLengthMax);
			}
		}

		if (errMsg == '\0')
		{
			if (!m_wndImageObjectPropList.Create(dwViewStyle, rectDummy, this, IDC_PROPSIMAGEOBJPROPS))
				errMsg = "Failed to create Image Object Properties Grid";
			else
			{
				m_wndImageObjectPropList.EnableHeaderCtrl(FALSE);
				m_wndImageObjectPropList.EnableDescriptionArea();
				m_wndImageObjectPropList.SetVSDotNetLook();
				m_wndImageObjectPropList.MarkModifiedProperties();
				m_wndImageObjectPropList.ExpandAll(FALSE);
				m_wndImageObjectPropList.SetAlphabeticMode(FALSE);

				SetFontForControls();

				rc = 0;
			}
		}
		if ( rc != 0 )
			CArchiveProcGUIApp::UserErrorMsg("Fatal Error", errMsg, "unable to recover", "restart application",  MB_ICONSTOP | MB_OK );
	}
	return rc;
}

void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnSize()", "change size cx=%d, cy=%d", cx, cy );
#endif
//!!!!!!!!!!!!!!!
	CDockablePane::OnSize(nType, cx, cy);

	if ( (m_cxSize != cx) || (m_cySize != cy))
	{
		m_cxSize = cx;
		m_cySize = cy;
		AdjustLayout();
	}
}

void CPropertiesWnd::OnExpandAllProperties()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnExpandAllProperties()", "expand props");
#endif
//!!!!!!!!!!!!!!!

	m_wndImagePropList.ExpandAll();
	m_wndImageObjectPropList.ExpandAll();
}

void CPropertiesWnd::OnUpdateExpandAllProperties(CCmdUI* /* pCmdUI */)
{
}

void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnSetFocus()", "set focus");
#endif
//!!!!!!!!!!!!!!!

	CDockablePane::OnSetFocus(pOldWnd);
	m_wndImageTypeCombo.SetFocus();
	//m_wndImageObjectPropList.SetFocus();
}


void CPropertiesWnd::OnEditCut()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnEditCut()", "cut");
#endif
//!!!!!!!!!!!!!!!
	if ( GetFocus()->GetSafeHwnd() == m_ImageObjectNotesCtrl.GetSafeHwnd())
		m_ImageObjectNotesCtrl.Cut();
	if ( GetFocus()->GetSafeHwnd() == m_ImageNotesCtrl.GetSafeHwnd())
		m_ImageNotesCtrl.Cut();

}

void CPropertiesWnd::OnEditCopy()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnEditCopy()", "copy");
#endif
//!!!!!!!!!!!!!!!

	if ( GetFocus()->GetSafeHwnd() == m_ImageObjectNotesCtrl.GetSafeHwnd())
		m_ImageObjectNotesCtrl.Copy();
	if ( GetFocus()->GetSafeHwnd() == m_ImageNotesCtrl.GetSafeHwnd())
		m_ImageNotesCtrl.Copy();
}

void CPropertiesWnd::OnEditPaste()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnEditPaste()", "paste");
#endif
//!!!!!!!!!!!!!!!

	if ( GetFocus()->GetSafeHwnd() == m_ImageObjectNotesCtrl.GetSafeHwnd())
		m_ImageObjectNotesCtrl.Paste();
	if ( GetFocus()->GetSafeHwnd() == m_ImageNotesCtrl.GetSafeHwnd())
		m_ImageNotesCtrl.Paste();
}

void CPropertiesWnd::OnThumbChangeBrightness(NMHDR *pNMHDR, LRESULT *pResult)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnThumbChangeBrightness()", "change brightness" );
#endif
//!!!!!!!!!!!!!!!
	if (m_UpdatingUI == false)
	{
		// This feature requires Windows Vista or greater.
		// The symbol _WIN32_WINNT must be >= 0x0600.
		NMTRBTHUMBPOSCHANGING *pNMTPC = reinterpret_cast<NMTRBTHUMBPOSCHANGING *>(pNMHDR);

		CArchiveProcGUIDoc *pDoc = CArchiveProcGUIDoc::GetActiveDoc();
		if ((pDoc != '\0') && (pNMTPC != '\0'))
		{
			m_UpdatingUI = true;
			pDoc->DoChangeBrightness(pNMTPC->dwPos);
			m_UpdatingUI = false;
		}
	}

	*pResult = 0;
}

void CPropertiesWnd::OnThumbChangeContrast(NMHDR *pNMHDR, LRESULT *pResult)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnThumbChangeContrast()", "change contrast" );
#endif
//!!!!!!!!!!!!!!!

	if (m_UpdatingUI == false)
	{
		// This feature requires Windows Vista or greater.
		// The symbol _WIN32_WINNT must be >= 0x0600.
		NMTRBTHUMBPOSCHANGING *pNMTPC = reinterpret_cast<NMTRBTHUMBPOSCHANGING *>(pNMHDR);

		CArchiveProcGUIDoc *pDoc = CArchiveProcGUIDoc::GetActiveDoc();
		if ((pDoc != '\0') && (pNMTPC != '\0'))
		{
			m_UpdatingUI = true;
			pDoc->DoChangeContrast(pNMTPC->dwPos);
			m_UpdatingUI = false;
		}
	}
	*pResult = 0;
}

void CPropertiesWnd::OnImageTypeSelChange()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnImageTypeSelChange()", "update properties window to reflect change of Image Type");
#endif
//!!!!!!!!!!!!!!!

	if (m_UpdatingUI == true)
		CancelImageTypeSelChange();
	else
	{
		int nIndex = m_wndImageTypeCombo.GetCurSel();
		if (nIndex != CB_ERR)
		{
			ImageType *pNewSelImageType = reinterpret_cast<ImageType *>(m_wndImageTypeCombo.GetItemDataPtr(nIndex));

			CArchiveProcGUIDoc *pDoc = CArchiveProcGUIDoc::GetActiveDoc();
			if ((pDoc != '\0') && (pNewSelImageType != '\0'))
			{
				ImageProps *pSelImageProps = '\0';
				if ((pSelImageProps = pDoc->GetSelImageProperties()) != '\0')
				{
					if ( pNewSelImageType != pSelImageProps->GetSelImageType())
					{
						//ImageObject *pImageObject = '\0';
						//int ObjCnt = pSelImageProps->GetImageObjectCnt();
						//for (int x = 0; x < ObjCnt; x++ )
						//{
						//	if ((pImageObject = pSelImageProps->GetNextIncompatibleImageObject(x, pNewSelImageType)) != '\0')
						//	{
						//		//std::string msg("delete image object: ");
						//		//msg += pImageObject->GetDisplayName();
						//		//msg += "? (";
						//		//msg += pImageObject->GetNote();
						//		//std::string note(pImageObject->GetNote());
						//		//msg += note.substr(0, CPropertiesWnd::ImageObjNoteDisplayLength);
						//		//msg += ")";

						//		//if (CArchiveProcGUIApp::UserMsg(msg.c_str(), "Yes to delete, No to abort Image Type change", MB_YESNO | MB_ICONQUESTION ) != IDYES)
						//		//{
						//		//	Abort = true;
						//		//	break;
						//		//}
						//	}
						//}
						pSelImageProps->SetSelImageType(pNewSelImageType, pDoc->GetSelImageObjectTypeTool());	//delete
					}

					if ( SetImageDisplay(pSelImageProps)  )
					{
						CArchiveProcGUIDoc::GetActiveDoc()->DoUpdateAllViews(NULL, CArchiveProcGUIDoc::UpdateAllViewsSetNewImageType, '\0');
						
						if (LoadImageObjectCB(pSelImageProps, pDoc->GetSelImageObjectTypeTool()) )
						{
							SetImageObjectDisplay(pSelImageProps->GetSelImageObject());
						}
					}
				}
			}
		}
	}
}

void CPropertiesWnd::OnImageObjectSelChange()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::OnImageObjectSelChange()", "update properties window to reflect change of Image Object");
#endif
//!!!!!!!!!!!!!!!

	int nIndex = m_wndImageObjectCombo.GetCurSel();
	if (nIndex != CB_ERR)
	{
		ImageObject *pNewSelImageObject = reinterpret_cast<ImageObject *>(m_wndImageObjectCombo.GetItemDataPtr(nIndex));
		ImageProps *pSelImageProps = GetSelImageProperties();
		if (pSelImageProps != '\0' )
		{
			if ( pNewSelImageObject != pSelImageProps->GetSelImageObject())
			{

				UpdateData(TRUE);

				if ( SaveImageObjectProperties(pSelImageProps) )
				{
					if (pSelImageProps->SetSelImageObject(pNewSelImageObject) )		
						LoadImageObjectProperties(GetSelImageProperties());			//GetSelImageProperties() now relates to pNewSelImageObject
				}
			}
			SetImageObjectDisplay(pSelImageProps->GetSelImageObject());
			CArchiveProcGUIDoc::GetActiveDoc()->DoUpdateAllViews(NULL, CArchiveProcGUIDoc::UpdateAllViewsSetNewImageObject, '\0');
		}
	}

	UpdateData(FALSE);
}

void  CPropertiesWnd::LoadProperties(ImageProps *pSelImageProps, ImageObjectTypeTool *pTool, ImageDataset *pImageDataset)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::LoadProperties()", "load properties window for selected image [%s]", (pSelImageProps != '\0') ? pSelImageProps->GetDicomRef(): "pSelImageProps is null");
#endif
//!!!!!!!!!!!!!!!

	ClearImageDisplay();
	ClearImageObjectDisplay();

	if (pSelImageProps->GetDicomRef() != '\0')
	{
		if ( LoadImageTypeCB (pSelImageProps, pImageDataset))
		{
			OnImageTypeSelChange();	

			//sequence of events on OnImageTypeSelChange();
			//...
			//if ( SetImageDisplay(pSelImageProps)  )
			//{
			//	if (LoadImageObjectCB(pSelImageProps, pTool) )
			//	{
			//		OnImageObjectSelChange();
			//
			//		if ((pSelImageProps != '\0') && (pSelImageProps->GetSelImageObject() != '\0'))
			//			SetImageObjectDisplay(pSelImageProps->GetSelImageObject());
			//	}
			//}
		}
	}
	UpdateData(FALSE);
}

void   CPropertiesWnd::UpdateProperties(ImageProps *pSelImageProps, int lHint)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::UpdateProperties()", "lHint=%s, update properties window for image [%s]", CArchiveProcGUIDoc::GetUpdateHintStr(lHint), (pSelImageProps != '\0') ? pSelImageProps->GetDicomRef(): "pProps is null" );
#endif
//!!!!!!!!!!!!!!
	if ( pSelImageProps != '\0')
	{
		if ( lHint == CArchiveProcGUIDoc::UpdateAllViewsCloseDoc)
		{
			ClearImageDisplay();
			m_wndImageTypeCombo.ResetContent();
			ClearImageObjectDisplay();
			m_wndImageObjectCombo.ResetContent();
			UpdateData(FALSE);
		}
		else if (lHint == CArchiveProcGUIDoc::UpdateAllViewsSetBrightnessContrast )
		{
			m_ImageBrightnessCtrl.SetPos(pSelImageProps->GetBrightnessValue());
			m_ImageContrastCtrl.SetPos(pSelImageProps->GetContrastValue());
		}
		else if (lHint == CArchiveProcGUIDoc::UpdateAllViewsDeleteImageObject)
		{
			CArchiveProcGUIDoc *pDoc = CArchiveProcGUIDoc::GetActiveDoc();
			if (pDoc != '\0' )
			{
				ImageProps *pSelImageProps = '\0';
				if ((pSelImageProps = pDoc->GetSelImageProperties()) != '\0')
					LoadImageObjectCB(pSelImageProps, pDoc->GetSelImageObjectTypeTool());
			}
		}
		else if (lHint == CArchiveProcGUIDoc::UpdateAllViewsCompleteImageObject)
		{
			CArchiveProcGUIDoc *pDoc = CArchiveProcGUIDoc::GetActiveDoc();
			if (pDoc != '\0' )
			{
				ImageProps *pSelImageProps = '\0';
				if ((pSelImageProps = pDoc->GetSelImageProperties()) != '\0')
					SelectImageObjectCB(pSelImageProps->GetSelImageObject());
			}
		}
	}
}

bool  CPropertiesWnd::SaveProperties(ImageProps *pSelImageProps)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::SaveProperties()", "save contents of properties window for image [%s]", (pSelImageProps != '\0') ? pSelImageProps->GetDicomRef(): "pProps is null" );
#endif
//!!!!!!!!!!!!!!!

	bool rc = false;

	UpdateData(TRUE);
	if ( SaveImageProperties(pSelImageProps))
	{
		if (SaveImageObjectProperties(pSelImageProps))
		{
			rc = true;			//Todo - set true only if the properties have changed
		}
	}
	return  rc;
}

bool    CPropertiesWnd::SaveImageProperties(ImageProps *pSelImageProps)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::SaveImageProperties()", "save image part of properties window for this image");
#endif
//!!!!!!!!!!!!!!!
	bool rc = true;

	if (pSelImageProps != '\0') 
	{
		CString DicomRef(pSelImageProps->GetDicomRef());
		if (DicomRef == m_ImageDicomRef )
		{
			pSelImageProps->SetBrightness(m_ImageBrightnessCtrl.GetPos());
			pSelImageProps->SetContrast(m_ImageContrastCtrl.GetPos());

			if ( m_ImageNotes.GetLength() <= ImageProps::NotesLengthMax )
			{
				char Temp[ImageProps::NotesLengthMax+1];
				wcstombs(Temp, m_ImageNotes, ImageProps::NotesLengthMax );
				pSelImageProps->SetNotes(Temp);
			}

			ImageProp *pImageProp = '\0';
			ImageTypeProp *pImagePropType = '\0';
			ImagePropInteger *pPropInt = '\0';
			ImagePropTextLine *pPropStr = '\0';
			CMFCPropertyGridProperty* pGridProp = '\0';
			char TempName[ImageProps::NameLengthMax+1];			//ImageDataset::MakeWellFormedAttributeName() ensures name length <= ImageProps::NameLengthMax
			char TempValue[ImageProps::NotesLengthMax+1];		//TODO: LoadImageProperties() and LoadImageObjectProperties() ensures value length <= ImageProps::NotesLengthMax

			int cnt = m_wndImagePropList.GetPropertyCount();
			for (int x = 0; x < cnt ; x++ )
			{
				if ( ( pGridProp = m_wndImagePropList.GetProperty(x)) != '\0')
				{
					CString PropGridName (pGridProp->GetName());				
					wcstombs(TempName, PropGridName, ImageProps::NameLengthMax );

					if ( pImageProp = pSelImageProps->GetImageProperty(TempName))
					{											//TODO: exploit polymorphism: pImageProp->SetPropValue(MxUtils::WideCharsToAscii_1(pGridProp->GetValue()));															
						if ((pImagePropType = pImageProp->GetOwner()) != '\0')
						{
							std::string controlType = pImagePropType->GetControl();		
							if ( controlType == ImageProp::xmlCtrlSLEdit)
							{
								if ((pPropStr = dynamic_cast<ImagePropTextLine *>(pImageProp)) != '\0')
								{
									CString PropGridValue (pGridProp->GetValue());
									wcstombs(TempValue, PropGridValue, ImageProps::NotesLengthMax );
									pPropStr->SetPropValue(TempValue);
								}
							}
							if ( controlType == ImageProp::xmlCtrlSpin)
							{
								if ((pPropInt = dynamic_cast<ImagePropInteger *>(pImageProp)) != '\0')
								{
									CString PropGridValue (pGridProp->GetValue());
									wcstombs(TempValue, PropGridValue, ImageProps::NotesLengthMax );
									pPropInt->SetPropValue(TempValue);
								}
							}
						}
					}
				}
			}
		}
	}
	return rc;
}


bool    CPropertiesWnd::SaveImageObjectProperties(ImageProps *pSelImageProps)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::SaveImageObjectProperties()", "save image object part of properties window for this image object");
#endif
//!!!!!!!!!!!!!!!

	bool rc = true;

	if (pSelImageProps != '\0' )
	{
		CString DicomRef(pSelImageProps->GetDicomRef());
		if (DicomRef == m_ImageDicomRef )
		{
			if ( m_ImageObjectNotes.GetLength() <= ImageProps::NotesLengthMax )
			{
				ImageObject *pSelImageObject = '\0';
				if ( (pSelImageObject = pSelImageProps->GetSelImageObject()) != '\0')
				{
					char Temp[ImageProps::NotesLengthMax+1];
					wcstombs(Temp, m_ImageObjectNotes, ImageProps::NotesLengthMax );
					pSelImageObject->SetNote(Temp);
				}
			}

			ImageProp *pImageProp = '\0';
			ImageTypeProp *pImagePropType = '\0';
			ImagePropInteger *pPropInt = '\0';
			ImagePropTextLine *pPropStr = '\0';
			CMFCPropertyGridProperty* pGridProp = '\0';
			char TempName[ImageProps::NameLengthMax+1];			//ImageDataset::MakeWellFormedAttributeName() ensures name length <= ImageProps::NameLengthMax
			char TempValue[ImageProps::NotesLengthMax+1];		//TODO: LoadImageProperties() and LoadImageObjectProperties() ensures value length <= ImageProps::NotesLengthMax

			int cnt = m_wndImageObjectPropList.GetPropertyCount();
			for (int x = 0; x < cnt ; x++ )
			{
				if ( ( pGridProp =  m_wndImageObjectPropList.GetProperty(x)) != '\0')
				{
					CString PropGridName (pGridProp->GetName());				
					wcstombs(TempName, PropGridName, ImageProps::NameLengthMax );

					if ( pImageProp = pSelImageProps->GetSelImageObjectProperty(TempName))
					{
						if ((pImagePropType = pImageProp->GetOwner()) != '\0')
						{
							std::string controlType = pImagePropType->GetControl();		//TODO: pImagePropType->SetValue(pGridProp->GetValue(), pImageProp);
							if ( controlType == ImageProp::xmlCtrlSLEdit)
							{
								if ((pPropStr = dynamic_cast<ImagePropTextLine *>(pImageProp)) != '\0')
								{
									CString PropGridValue (pGridProp->GetValue());
									wcstombs(TempValue, PropGridValue, ImageProps::NotesLengthMax );
									pPropStr->SetPropValue(TempValue);
								}
							}
							if ( controlType == ImageProp::xmlCtrlSpin)
							{
								if ((pPropInt = dynamic_cast<ImagePropInteger *>(pImageProp)) != '\0')
								{
									CString PropGridValue (pGridProp->GetValue());
									wcstombs(TempValue, PropGridValue, ImageProps::NotesLengthMax );
									pPropInt->SetPropValue(TempValue);
								}
							}
						}
					}
				}
			}
		}
	}
	return rc;
}

bool CPropertiesWnd::LoadImageProperties(ImageProps *pSelImageProps)
{
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::LoadImageProperties()", "update properties window for this image");
#endif
//!!!!!!!!!!!!!!!

	if ( pSelImageProps != '\0')
	{
		ImageTypeProp *pImagePropType = '\0';
		ImageProp *pImageProp = '\0';
		int cnt = pSelImageProps->GetImagePropertyCnt();
		for (int x = 0; x < cnt; x++ )
		{
			if ( (pImageProp = pSelImageProps->GetImageProperty(x)) != '\0')
			{
				if ((pImagePropType = pImageProp->GetOwner()) != '\0')
				{
					CMFCPropertyGridProperty* pProp = '\0';
					ImagePropInteger *pPropInt = '\0';
					ImagePropTextLine *pPropStr = '\0';
					
					CString PropName(pImagePropType->GetName());
					CString PropPrompt(pImagePropType->GetPrompt());

					std::string controlType = pImagePropType->GetControl();
					if ( controlType == ImageProp::xmlCtrlSLEdit)
					{
						if ((pPropStr = dynamic_cast<ImagePropTextLine *>(pImageProp)) != '\0')
						{
							_variant_t val = pPropStr->GetPropValue();
							pProp = new CMFCPropertyGridProperty(PropName, val, PropPrompt);
						}
					}
					if ( controlType == ImageProp::xmlCtrlSpin)
					{
						if ((pPropInt = dynamic_cast<ImagePropInteger *>(pImageProp)) != '\0')
						{
							_variant_t val = pPropInt->GetPropValueInt();
							pProp = new CMFCPropertyGridProperty(PropName, val, PropPrompt);
							pProp->EnableSpinControl(TRUE, pImagePropType->GetValMin(), pImagePropType->GetValMax());
						}
					}
					if ( pProp != '\0')
					{
						pProp->AllowEdit(TRUE);
						m_wndImagePropList.AddProperty(pProp);
						m_wndImagePropList.AdjustLayout();
					}
				}
			}
		}
		rc = true;
	}
	return rc;
}

bool CPropertiesWnd::LoadImageTypeCB(ImageProps *pSelImageProps, ImageDataset *pImageDataset)
{
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::LoadImageTypeCB()", "load Image Type Combo with Image Types for this image");
#endif
//!!!!!!!!!!!!!!!

	m_wndImageTypeCombo.ResetContent();

	if ((pSelImageProps != '\0') && (pImageDataset != '\0'))
	{
		int index = -1;
		ImageType *pImageType = '\0';
		int cnt = pImageDataset->GetImageTypeCnt();		//must have atleast (unclassified) as added by default even if not in IDF
		if (cnt > 0 )
		{
			for (int x = 0; x < cnt; x++ )
			{
				 if ((pImageType = pImageDataset->GetImageType(x)) != '\0')
				 {
						CString imageTypeName("Image Type: ");
						imageTypeName += pImageType->GetName();
						if ( (index = m_wndImageTypeCombo.AddString(imageTypeName)) >= 0 )
							m_wndImageTypeCombo.SetItemDataPtr(index, pImageType);
				 }
			}
			if (index >= 0 )
			{
				for (int x = 0; x < m_wndImageTypeCombo.GetCount(); x++)
				{
					if ( m_wndImageTypeCombo.GetItemDataPtr(x) ==  pSelImageProps->GetSelImageType())
					{		 
						m_wndImageTypeCombo.SetCurSel(x);
						rc = true;
						break;
					}
				}
			}
		}
	}
	return rc;
}


bool  CPropertiesWnd::LoadImageObjectCB(ImageProps *pSelImageProps, ImageObjectTypeTool *pTool)
{
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::LoadImageTypeCB()", "load Image Object Combo with Image objects for this image type");
#endif
//!!!!!!!!!!!!!!!

	if (pSelImageProps != '\0')
	{
		int index = -1;
		ImageObject *pImageObj = '\0';
		SelectTool *pSelectTool = NULL;

		std::string selectTypeName(SelectType::baseClassName);
		std::string imageObjectTypeName;

		m_wndImageObjectCombo.ResetContent();

		int cnt = pSelImageProps->GetImageObjectCnt();
		for (int x = 0; x < cnt; x++ )
		{
			if ((pImageObj = pSelImageProps->GetImageObject(x)) != '\0')
			{
				//if ((pImageObj->GetImageObjectType() == pTool->GetImageObjectType()) || (selectTypeName == pTool->GetImageObjectType()->GetBaseClassName()))
				//{
					CString imageObjectTypeName(pImageObj->GetDisplayName());
					if ( (index = m_wndImageObjectCombo.AddString(imageObjectTypeName)) >= 0 )
						m_wndImageObjectCombo.SetItemDataPtr(index, pImageObj);
				//}
			}
		}
		if (index >= 0 )
			SelectImageObjectCB(pSelImageProps->GetSelImageObject());
		rc = true;
	}
	return rc;
}

bool CPropertiesWnd::SelectImageObjectCB(ImageObject *pImageObject)
{
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::SelectImageObjectCB()", "select Image Object [%s] in Object Combo", (pImageObject != '\0') ? pImageObject->GetDisplayName() : "pImageObject is null");
#endif
//!!!!!!!!!!!!!!!

	int cnt = m_wndImageObjectCombo.GetCount();
	for (int x = 0; x < cnt; x++)
	{
		if ( m_wndImageObjectCombo.GetItemDataPtr(x) ==  pImageObject)
		{		 
			rc = (m_wndImageObjectCombo.SetCurSel(x) != CB_ERR) ? true : false;
			break;
		}
	}
	if ((rc == false) && (cnt > 0))
		rc = (m_wndImageObjectCombo.SetCurSel(0) != CB_ERR) ? true : false;

	if (rc == true) 
		OnImageObjectSelChange();

	return rc;
}

bool  CPropertiesWnd::LoadImageObjectProperties(ImageProps *pSelImageProps)
{
	bool rc = false;

//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::LoadImageTypeCB()", "load Property Window Image Object Properties Combo with values for this image object");
#endif
//!!!!!!!!!!!!!!!

	if (pSelImageProps != '\0')
	{
		ImageTypeProp *pImagePropType = '\0';
		ImageProp *pImageProp = '\0';
		ImageObject *pSelImageObject = '\0';

		if ( (pSelImageObject = pSelImageProps->GetSelImageObject()) != '\0')
		{
			int cnt = pSelImageObject->GetPropertyCnt();
			for (int x = 0; x < cnt; x++ )
			{
				if ( (pImageProp = pSelImageObject->GetProperty(x)) != '\0')
				{
					if ((pImagePropType = pImageProp->GetOwner()) != '\0')
					{
						CMFCPropertyGridProperty* pProp = '\0';
						ImagePropInteger *pPropInt = '\0';
						ImagePropTextLine *pPropStr = '\0';
					
						CString PropName(pImagePropType->GetName());
						CString PropPrompt(pImagePropType->GetPrompt());

						std::string controlType = pImagePropType->GetControl();
						if ( controlType == ImageProp::xmlCtrlSLEdit)
						{
							if ((pPropStr = dynamic_cast<ImagePropTextLine *>(pImageProp)) != '\0')
							{
								_variant_t val = pPropStr->GetPropValue();
								pProp = new CMFCPropertyGridProperty(PropName, val, PropPrompt);
							}
						}
						if ( controlType == ImageProp::xmlCtrlSpin)
						{
							if ((pPropInt = dynamic_cast<ImagePropInteger *>(pImageProp)) != '\0')
							{
								_variant_t val = pPropInt->GetPropValueInt();
								pProp = new CMFCPropertyGridProperty(PropName, val, PropPrompt);
								pProp->EnableSpinControl(TRUE, pImagePropType->GetValMin(), pImagePropType->GetValMax());
							}
						}
						if ( pProp != '\0')
						{
							pProp->AllowEdit(TRUE);
							m_wndImageObjectPropList.AddProperty(pProp);
							m_wndImageObjectPropList.AdjustLayout();
						}
					}
				}
			}
		}
		rc = true;
	}
	return rc;
}

bool  CPropertiesWnd::SetImageDisplay(ImageProps *pSelImageProps)
{
	bool rc = false;
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::SetImageDisplay()", "Set display for image [%s]", (pSelImageProps != '\0') ? pSelImageProps->GetDicomRef() : "pImageProps is null" );
#endif
//!!!!!!!!!!!!!!!

	ClearImageDisplay();

	if ( pSelImageProps != '\0')
	{
		m_ImageDicomRef = pSelImageProps->GetDicomRef();

		m_ImageBrightnessCtrl.EnableWindow(TRUE);
		m_ImageBrightnessCtrl.SetPos(pSelImageProps->GetBrightnessValue());
		m_ImageContrastCtrl.EnableWindow(TRUE);
		m_ImageContrastCtrl.SetPos(pSelImageProps->GetContrastValue());

		m_ImageNotesCtrl.SetReadOnly(FALSE);
		m_ImageNotes = pSelImageProps->GetNotes();

		if ( LoadImageProperties(pSelImageProps) )
		{
			UpdateData(FALSE);
			rc = true;
		}
	}
	return rc;
}

void  CPropertiesWnd::SetImageObjectDisplay(ImageObject *pSelImageObject)
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::SetImageObjectDisplay()", "Set display for image object [%s]", (pSelImageObject != '\0') ? pSelImageObject->GetDisplayName() : "pSelImageObject is null" );
#endif
//!!!!!!!!!!!!!!!

	ClearImageObjectDisplay();

	if ( pSelImageObject != '\0')
	{
		m_ImageObjectNotesCtrl.SetReadOnly(FALSE);
		m_ImageObjectNotes = pSelImageObject->GetNote();

		if (LoadImageObjectProperties(GetSelImageProperties()))
			UpdateData(FALSE);

		m_pSelImageObject = pSelImageObject;
	}
}

void CPropertiesWnd::ClearImageDisplay()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::ClearImageDisplay()", "clear contents of image prop controls in property window");
#endif
//!!!!!!!!!!!!!!!

	m_ImageDicomRef = L"Image: ";

	m_ImageBrightnessCtrl.SetPos(atoi(ImageProps::BrightnessMid));
	m_ImageBrightnessCtrl.EnableWindow(FALSE);
	m_ImageContrastCtrl.SetPos(atoi(ImageProps::ContrastMid));
	m_ImageContrastCtrl.EnableWindow(FALSE);

	m_ImageNotes = L"";
	m_ImageNotesCtrl.SetReadOnly(TRUE);

	m_wndImagePropList.RemoveAll();
	m_wndImagePropList.AdjustLayout();
}

void CPropertiesWnd::ClearImageObjectDisplay()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::ClearImageObjectDisplay()", "clear contents of image object prop controls in property window");
#endif
//!!!!!!!!!!!!!!!

	m_ImageObjectNotes = L"";
	m_ImageObjectNotesCtrl.SetReadOnly(TRUE);

	m_wndImageObjectPropList.RemoveAll();
	m_wndImageObjectPropList.AdjustLayout();
}

void CPropertiesWnd::SetFontForControls()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::SetFontForControls()", "set fonts for controls in property window");
#endif
//!!!!!!!!!!!!!!!

	::DeleteObject(m_fntBoldPropList.Detach());
	::DeleteObject(m_fntPropList.Detach());
	

	LOGFONT lf;
	afxGlobalData.fontRegular.GetLogFont(&lf);

	NONCLIENTMETRICS info;
	info.cbSize = sizeof(info);

	afxGlobalData.GetNonClientMetrics(info);

	m_ctrlMinHeaderHt = (info.lfMenuFont.lfHeight >= 0) ? info.lfMenuFont.lfHeight + 3 : -info.lfMenuFont.lfHeight + 3;
	lf.lfHeight = info.lfMenuFont.lfHeight;
	lf.lfWeight = FW_BOLD; 
	lf.lfItalic = info.lfMenuFont.lfItalic;

	m_fntBoldPropList.CreateFontIndirect(&lf);

	m_ImageDicomRefCtrl.SetFont(&m_fntBoldPropList);
	m_ImageObjectHeaderCtrl.SetFont(&m_fntBoldPropList);

	lf.lfWeight = info.lfMenuFont.lfWeight;
	m_fntPropList.CreateFontIndirect(&lf);

	m_ImageBrightnessHeaderCtrl.SetFont(&m_fntPropList);
	m_ImageContrastHeaderCtrl.SetFont(&m_fntPropList);
	m_wndImageTypeCombo.SetFont(&m_fntPropList);
	m_ImageNotesHeaderCtrl.SetFont(&m_fntPropList);
	m_ImageNotesCtrl.SetFont(&m_fntPropList);
	m_wndImagePropList.SetFont(&m_fntPropList);

	m_SeperatorCtrl.SetFont(&m_fntPropList);

	m_wndImageObjectCombo.SetFont(&m_fntPropList);
	m_ImageObjectNotesHeaderCtrl.SetFont(&m_fntPropList);
	m_ImageObjectNotesCtrl.SetFont(&m_fntPropList);
	m_wndImageObjectPropList.SetFont(&m_fntPropList);
}


void CPropertiesWnd::CancelImageTypeSelChange()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::CancelImageTypeSelChange()", "cancel change to ImageType, return to previous selection");
#endif
//!!!!!!!!!!!!!!!

	ImageType *pCBSelImageType = '\0';
	ImageType *pDocSelImageType = '\0';
	CArchiveProcGUIDoc *pDoc = CArchiveProcGUIDoc::GetActiveDoc();
	if (pDoc != '\0') 
	{
		ImageProps *pSelImageProps = '\0';
		if ((pSelImageProps = pDoc->GetSelImageProperties()) != '\0')
			pDocSelImageType = pSelImageProps->GetSelImageType();
	}

	int nIndex = m_wndImageTypeCombo.GetCurSel();
	if (nIndex != CB_ERR)
		pCBSelImageType = reinterpret_cast<ImageType *>(m_wndImageTypeCombo.GetItemDataPtr(nIndex));

	if ( (pDocSelImageType != '\0') && (pCBSelImageType != pDocSelImageType))
	{
		for (int x = 0; x < m_wndImageTypeCombo.GetCount(); x++)
		{
			if ( m_wndImageTypeCombo.GetItemDataPtr(x) ==  pDocSelImageType)
			{		 
				m_wndImageTypeCombo.SetCurSel(x);
				break;
			}
		}
	}
}

void CPropertiesWnd::CancelImageObjectSelChange()
{
//!!!!!!!!!!!!!!!
#ifdef _DEBUG
	MxUtils::OutputDebugMsg("CPropertiesWnd::CancelImageObjectSelChange()", "cancel change to ImageObject, return to previous selection");
#endif
//!!!!!!!!!!!!!!!

	ImageObject *pCBSelImageObject = '\0';
	ImageObject *pDocSelImageObject = '\0';
	CArchiveProcGUIDoc *pDoc = CArchiveProcGUIDoc::GetActiveDoc();
	if (pDoc != '\0') 
	{
		ImageProps *pSelImageProps = '\0';
		if ((pSelImageProps = pDoc->GetSelImageProperties()) != '\0')
			pDocSelImageObject = pSelImageProps->GetSelImageObject();
	}

	int nIndex = m_wndImageObjectCombo.GetCurSel();
	if (nIndex != CB_ERR)
		pCBSelImageObject = reinterpret_cast<ImageObject *>(m_wndImageObjectCombo.GetItemDataPtr(nIndex));

	if ( (pDocSelImageObject != '\0') && (pCBSelImageObject != pDocSelImageObject))
		SelectImageObjectCB(pDocSelImageObject);

}

//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------



